﻿using nplJobsCommon.Employeer;
using nplJobsCommon.JobSeeker;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace nplJobsDAL.Delete
{
    public class DeleteAppliedJob : DataAccessBase
    {
        public bool IsDeleted { get; set; }

        private DataTable dtAppliedJobToDisplay;
        public DataTable AppliedJobToDisplay
        {
            get
            {
                return dtAppliedJobToDisplay;
            }
            set
            {
                this.dtAppliedJobToDisplay = value;
            }
        }

        public DeleteAppliedJob()
        {
            StoredProcedureName = StoredProcedure.Name.spDeleteAppliedJobByID.ToString();
        }
        public void invoke()
        {
            DeleteAppliedJobDataParameters deleteAppliedJobDataParameters = new DeleteAppliedJobDataParameters(AppliedJobToDisplay);
            DataBaseHelper dbHelper = new DataBaseHelper(StoredProcedureName);
            dbHelper.Parameters = deleteAppliedJobDataParameters.Parameters;
            dbHelper.RunScalar();

            if (deleteAppliedJobDataParameters.Parameters[1].Value != null)
            {
                IsDeleted = bool.Parse(deleteAppliedJobDataParameters.Parameters[1].Value.ToString());
            }
        }
    }

    #region SQL Parameters for  Delete Applied Job delete
    public class DeleteAppliedJobDataParameters
    {
        private DataTable dtsAppliedJobs;
        public bool isDeleted;
        public DeleteAppliedJobDataParameters(DataTable dtAppliedJobToDisplay)
        {
            this.dtsAppliedJobs = dtAppliedJobToDisplay;
            Build();
        }

        private void Build()
        {
            SqlParameter[] parameters = 
                {
                    new SqlParameter("@AppliedJobID", this.dtsAppliedJobs),
                    new SqlParameter("@IsDeleted",isDeleted){ Direction =System.Data.ParameterDirection.Output}
                };

            Parameters = parameters;
        }

        public SqlParameter[] Parameters { get; set; }
    }
    #endregion
}
